home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-23 | 4.2 KB | 157 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CBlurBehavior.cp ©1999 Eric Traut
- // ===========================================================================
-
- #include "CBlurBehavior.h"
- #include "CShadowWindow.h"
-
-
- // ---------------------------------------------------------------------------
- // • CBlurBehavior
- // ---------------------------------------------------------------------------
-
- CBlurBehavior::CBlurBehavior(
- CShadowWindow & inShadowWindow)
- : COffscreenBehavior(inShadowWindow, true)
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • SyncWithShadowWindow
- // ---------------------------------------------------------------------------
-
- Boolean
- CBlurBehavior::SyncWithShadowWindow(void)
- {
- Boolean didSync;
-
- didSync = COffscreenBehavior::SyncWithShadowWindow();
-
- if (didSync)
- {
- // Recalculate our blur rect
- CWindowRecord * macWindow = mShadowWindow.GetMacWindow();
- mBlurRect = macWindow->port.portRect;
-
- mBlurRect.right -= 15;
- mBlurRect.bottom -= 15;
- mBlurRect.top += 22;
- }
-
- return didSync;
- }
-
-
- // ---------------------------------------------------------------------------
- // • RenderToGWorld
- // ---------------------------------------------------------------------------
-
- void
- CBlurBehavior::AccumColor(
- UInt16 inPixel,
- UInt32 & ioAccumRed,
- UInt32 & ioAccumGreen,
- UInt32 & ioAccumBlue,
- Fixed inFraction)
- {
- UInt32 red = (inPixel >> 10) & 0x1F;
- UInt32 green = (inPixel >> 5) & 0x1F;
- UInt32 blue = (inPixel & 0x1F);
-
- ioAccumRed += red * inFraction;
- ioAccumGreen += green * inFraction;
- ioAccumBlue += blue * inFraction;
- }
-
-
- // ---------------------------------------------------------------------------
- // • RenderToGWorld
- // ---------------------------------------------------------------------------
-
- Boolean
- CBlurBehavior::RenderToGWorld(
- StGWorldLocker & inBackingLocker,
- StGWorldLocker & inRenderingLocker)
- {
- UInt16 row;
- UInt16 column;
- UInt16 blurCount;
- UInt16 maxRow;
- UInt16 maxColumn;
- UInt16 srcRowWords;
- UInt16 destRowWords;
- UInt16 * srcRowPtr;
- UInt16 * destRowPtr;
- UInt16 * origDestRowPtr;
- PixMapPtr tempPixMap;
-
- tempPixMap = *inBackingLocker.GetPixMap();
- srcRowWords = (tempPixMap->rowBytes & 0x3FFF) / 2;
- srcRowPtr = reinterpret_cast<UInt16 *>(tempPixMap->baseAddr);
-
- tempPixMap = *inRenderingLocker.GetPixMap();
- destRowWords = (tempPixMap->rowBytes & 0x3FFF) / 2;
- destRowPtr = reinterpret_cast<UInt16 *>(tempPixMap->baseAddr);
- origDestRowPtr = destRowPtr;
-
- maxRow = tempPixMap->bounds.bottom - tempPixMap->bounds.top;
- maxColumn = tempPixMap->bounds.right - tempPixMap->bounds.left;
-
- // Do a blur effect.
- // Sean Parent (Photoshop architect) told me to do it this way.
- for (blurCount = 0; blurCount < 2; blurCount++)
- {
- for (row = 0; row < maxRow; row++)
- {
- for (column = 0; column < maxColumn; column++)
- {
- UInt32 accumRed = 0;
- UInt32 accumGreen = 0;
- UInt32 accumBlue = 0;
-
- if (column >= mBlurRect.left && column < mBlurRect.right &&
- row >= mBlurRect.top && row < mBlurRect.bottom)
- {
- if (column > mBlurRect.left)
- AccumColor(srcRowPtr[column - 1], accumRed, accumGreen, accumBlue, 0x00004000);
- else
- AccumColor(srcRowPtr[column], accumRed, accumGreen, accumBlue, 0x00004000);
-
- if (column < mBlurRect.right - 1)
- AccumColor(srcRowPtr[column + 1], accumRed, accumGreen, accumBlue, 0x00004000);
- else
- AccumColor(srcRowPtr[column], accumRed, accumGreen, accumBlue, 0x00004000);
-
- if (row > mBlurRect.top)
- AccumColor(srcRowPtr[column - srcRowWords], accumRed, accumGreen, accumBlue, 0x00004000);
- else
- AccumColor(srcRowPtr[column], accumRed, accumGreen, accumBlue, 0x00004000);
-
- if (row < mBlurRect.bottom - 1)
- AccumColor(srcRowPtr[column + srcRowWords], accumRed, accumGreen, accumBlue, 0x00004000);
- else
- AccumColor(srcRowPtr[column], accumRed, accumGreen, accumBlue, 0x00004000);
-
- destRowPtr[column] = ((accumRed >> 16) << 10) |
- ((accumGreen >> 16) << 5) |
- (accumBlue >> 16);
- }
- else
- {
- destRowPtr[column] = srcRowPtr[column];
- }
- }
-
- srcRowPtr += srcRowWords;
- destRowPtr += destRowWords;
- }
-
- srcRowPtr = destRowPtr = origDestRowPtr;
- }
-
- return true;
- }
-
-
-